<!-- 职级编辑弹窗 -->
<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form
        :model="where"
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>
        <el-row :gutter="15">
          <el-col :lg="6" :md="12">
              <el-form-item label="单据编号:">
                <el-input
                  clearable
                  v-model="where.danjNo"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :lg="6" :md="12">
              <el-form-item label="单位编号:">
                <el-input
                  clearable
                  v-model="where.danwNo"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :lg="6" :md="12">
              <el-form-item label="业务员:">
                <el-input
                  clearable
                  v-model="where.caigouStaff"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :lg="6" :md="12">
              <el-form-item label="商品编号:">
                <el-input
                  clearable
                  v-model="where.shangpNo"
                  placeholder=""/>
              </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="15">
            <el-col :lg="6" :md="12">
              <el-form-item label="批号:">
                <el-input
                  clearable
                  v-model="where.lot"
                  placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :lg="6" :md="12">
              <el-form-item label="入库类型:">
                <el-input
                  clearable
                  v-model="where.rukType"
                  placeholder=""/>
              </el-form-item>
            </el-col>
          <el-col :lg="6" :md="12">
              <el-form-item label="上传状态:">
                <el-select
                clearable
                v-model="where.zt"
                placeholder="请选择状态"
                class="ele-fluid">
                <el-option label="是" value="Y"/>
                <el-option label="否" value="N"/>
                <el-option label="E" value="E"/>
                <el-option label="H" value="H"/>
                <el-option label="ZT" value="ZT"/>
              </el-select>
              </el-form-item>
            </el-col>

          <el-col :lg="6" :md="12">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                size="small"
                @click="reload">查询
              </el-button>
              <el-button @click="reset" size="small">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
      
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        height="calc(100vh - 415px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar" v-if="false">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit(null)"
            >NC回写
          </el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            class="ele-btn-icon"
            @click="removeBatch"
            v-if="false"
            >删除
          </el-button>
        </template>
      </ele-pro-table>

      <div slot="footer">
        <el-button @click="updateVisible(false)">取消</el-button>
        <el-button
          type="primary"
          @click="save"
          >保存
        </el-button>
      </div>
    </el-card>
    </div>
  </template>
  
  <script>
  export default {
    name: 'LogQuery',
    data() {
      return {
        // 表单数据
        //form: Object.assign({status: 1}, this.dataItem),
        url: '/ncservicelog/index',
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'submitNo',
          label: '提交编号',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center'
        },
        {
          prop: 'requestBody',
          label: '提交报文',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'responseBody',
          label: '返回结果',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'responseCode',
          label: '返回状态',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'responseResult',
          label: '处理结果',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'submitTime',
          label: '提交时间',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },

      ],
      // 表格搜索条件
      where: {},

        // 表单验证规则
        rules: {
          name: [
            {required: true, message: '请输入职级名称', trigger: 'blur'}
          ],
          status: [
            {required: true, message: '请选择职级状态', trigger: 'blur'}
          ],
          sort: [
            {required: true, message: '请输入排序号', trigger: 'blur'}
          ]
        },
        // 提交状态
        loading: false,
        // 是否是修改
        isUpdate: false
      };
    },
    watch: {
      data() {
        if (this.dataItem) {
          this.form = Object.assign({}, this.dataItem);
          this.isUpdate = true;
        } else {
          this.form = {};
          this.isUpdate = false;
        }
      }
    },
    methods: {
      loaddata(){
        if (this.dataItem) {
          this.where.danjNo = this.dataItem.danjNo;
          this.$refs.table.reload();
        }        
      },
      /* 保存编辑 */
      save() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.loading = true;
            this.$http[this.isUpdate ? 'put' : 'post'](this.isUpdate ? '/level/edit' : '/level/add', this.form).then(res => {
              this.loading = false;
              if (res.data.code === 0) {
                this.$message.success(res.data.msg);
                if (!this.isUpdate) {
                  this.form = {};
                }
                this.updateVisible(false);
                this.$emit('done');
              } else {
                this.$message.error(res.data.msg);
              }
            }).catch(e => {
              this.loading = false;
              this.$message.error(e.message);
            });
          } else {
            return false;
          }
        });
      },
      /* 更新visible */
      updateVisible(value) {
        this.$emit('update:visible', value);
      }
    }
  }
  </script>
  
  <style scoped>
  </style>
  